package com.wlf.generate.entity;


import com.wlf.generate.utils.StringUtils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class Settings {

    /**
     * 项目名称
     */
    private String project = "example";
    /**
     * 包名
     */
    private String pPackage = "com.example.demo";

    private String projectComment;
    private String author;
    private String path1 = "com";
    private String path2 = "example";
    private String path3 = "demo";
    /**
     * 完整路径
     */
    private String pathAll;

    public Settings(String project, String pPackage, String projectComment, String author) {
        if (project != null){
            this.project = project;
        }
        if (pPackage != null){
            this.pPackage = pPackage;
        }
        this.projectComment = projectComment;
        this.author = author;
        String [] paths = pPackage.split("\\.");

        path1 = paths[0];
        path2 = paths.length>1?paths[1]:path2;
        path3 = paths.length>2?paths[2]:path3;
        pathAll = pPackage.replaceAll(".","/");
    }

    public Map<String,Object> getSettingMap(){
        Map<String,Object> map = new HashMap<String, Object>();
        Field[] declaredFields = Settings.class.getDeclaredFields();

        for (Field field : declaredFields) {
            field.setAccessible(true);
            try {
                map.put(field.getName(),field.get(this));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}
